package com.openlab.callsystem.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openlab.callsystem.entity.Log;
import com.openlab.callsystem.enums.BusinessType;
import com.openlab.callsystem.mapper.CallerMapper;
import com.openlab.callsystem.mapper.LogMapper;
import com.openlab.callsystem.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-11-14
 */
@Service
public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogService {
    @Autowired
    LogMapper logMapper;
    @Override
    public List<Log> queryAll() {
        return logMapper.queryAll();
    }
    @Autowired
    CallerMapper callerMapper;
    @Override
    public Integer calCount(Integer businessType) {
        return logMapper.calNumber(businessType);
    }

    @Override
    public Map<String, Map<String, List>> getChartsData() {
        Map<String,Map<String,List>> map=new HashMap();
        for (int i=1;i<6;i++){
            Map<String,Integer> dataMap = null;
            switch (i){
                case 1:dataMap=logMapper.queryAllByDay();break;//分天业务量
                case 2:dataMap=logMapper.queryByDay(BusinessType.Common.getValue());break;
                case 3:dataMap=logMapper.queryByDay(BusinessType.Vip.getValue());break;
                case 4:dataMap=logMapper.queryWorkload(BusinessType.Common.getValue());break;
                case 5:dataMap=logMapper.queryWorkload(BusinessType.Vip.getValue());break;
            }
            Map<String,List> getMap=new HashMap<>();
            ArrayList list=new ArrayList();
            for (String key:dataMap.keySet()){
                list.add(key);
            }
            getMap.put("key",list);
            list=new ArrayList();
            for (Integer value:dataMap.values()){
                list.add(value);
            }
            getMap.put("value",list);
            map.put("chart"+i,getMap);
        }

        return map;
    }

    @Override
    public Map<String, Integer> getIndexData() {
        Map<String,Integer> map=new HashMap<>();
        Integer viptoday=logMapper.queryTodayLogNumber(BusinessType.Vip.getValue());
        Integer commontoday=logMapper.queryTodayLogNumber(BusinessType.Common.getValue());
        map.put("vipToday",viptoday);
        map.put("commonToday",commontoday);
        map.put("vip",logMapper.calVip());
        map.put("common",logMapper.calCommon());
        return map;
    }


}
